package cn.elwy.rcp.ui.explorer.process;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.operation.IRunnableWithProgress;

import cn.elwy.rcp.core.model.ui.progress.ProgressMonitor;
import cn.elwy.rcp.ui.explorer.core.AppContext;
import cn.elwy.rcp.ui.explorer.core.service.BuilderModuleChoiceService;
import cn.elwy.rcp.ui.explorer.core.vo.BuilderModule;
import cn.elwy.rcp.ui.explorer.editor.ModuleChoiceModel;

/**
 * 更新SVN代码进程
 * @author huangsq
 * @version 1.0, 2014-10-15
 * @since 1.0, 2014-10-15
 */
public class LoadModuleProgress implements IRunnableWithProgress {

	private BuilderModuleChoiceService service = AppContext.getService(BuilderModuleChoiceService.ID,
			BuilderModuleChoiceService.class);

	private ModuleChoiceModel moduleChoiceModel;

	// private ProjectConfig projectConfig;
	// private List<BuilderModule> builderModules;

	public LoadModuleProgress(ModuleChoiceModel moduleChoiceModel) {
		this.moduleChoiceModel = moduleChoiceModel;
	}

	public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
		try {
			ProgressMonitor progressMonitor = new ProgressMonitor(monitor);
			monitor.beginTask("更新SVN代码", IProgressMonitor.UNKNOWN);

			moduleChoiceModel.setProgressMonitor(progressMonitor);
			moduleChoiceModel.setInput(null);
			List<BuilderModule> moduleList = moduleChoiceModel.getInput();
			moduleChoiceModel.setInput(moduleList);
		} finally {
			monitor.done();
		}
		if (monitor.isCanceled()) {
			throw new InterruptedException("The long running operation was cancelled");
		}
	}

	// public List<BuilderModule> getBuilderModules() {
	// return builderModules;
	// }

}
